<script lang="ts" setup>
// 这里导入一直失败，可能是 nodemailer 需要node服务
// 解决方案  用express搭建服务端，然后使用nodemailer
// import nodemailer from 'nodemailer';
const nodemailer = require('nodemailer');
import { useRouter } from 'vue-router';
const router = useRouter();

const props = defineProps({
  value: {
    type: String,
    default: '',
  },
});
onMounted(() => {});
const send = () => {
  message.info('开始发送');

  let transporter = nodemailer.createTransport({
    host: 'smtp.qq.com', //发送者邮箱服务端口,参考 https://github.com/nodemailer/nodemailer-wellknown/blob/master/services.json
    port: 465,
    secure: true,
    auth: {
      user: '652842002@qq.com', //发送者邮箱
      pass: 'yucoyduikohrbdif', //发送者邮箱授权码，不是登录或者独立密码，是你设置的smtp授权密码
    },
  });

  let mailOptions = {
    from: '"发送者 👻" <652842002@qq.com>', // sender address
    to: '2940500590@qq.com', // list of receivers
    subject: 'Hello ✔', // Subject line
    text: 'Hello world?', // plain text body
    html: '<b>Hello world?</b>', // html body
  };

  transporter.sendMail(mailOptions, (err, info) => {
    if (err) {
      console.log(err);
    } else {
      console.log(info);
    }
  });
};
</script>

<template>
  <div class="content" id="exportPdf">
    <a-space>
      <a-button type="primary" @click="send">发送</a-button>
      <a-button type="primary" danger @click="() => router.push('/index')">文件导出</a-button>
      <a-button type="primary" danger @click="() => router.push('/preview')">文件预览</a-button>
    </a-space>

    <br />
    <br />
    <hr />
  </div>
</template>

<style lang="less" scoped>
.content {
  width: 90vw;
  min-height: 90vh;
  margin: 3vh auto;
  padding: 20px;
  outline: 1px dashed #999;
}
</style>
